<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>nouveau engagement</title>

<!------------------------------ajax---------------------------->
<!-- <script type="text/javascript"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
    <script type="text/javascript"  src="http://malsup.github.com/jquery.form.js"></script> -->
	
<!---------------------for autocomplete--------------->
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-1.11.0.min.js');?>" ></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-ui-1.10.4/js/jquery-ui-1.10.4.min.js');?>" ></script>
	<link href="<?php echo base_url("assets/css/jquery-ui.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form css ----------------------->
	<link href="<?php echo base_url("assets/css/pure.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form validation ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.validate.js');?>" ></script>
<!---------------------for form mask input ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.mask.min.js');?>" ></script>


</head>
<body>
<?php
include_once('header.php');


// ----- populate $liste_des_fournisseurs array for autocomplete ----- //


$liste_des_charticles = array();
foreach ($charticles as $chart){
	array_push($liste_des_charticles, $chart->nom_art);
	
}
// ----- populate $liste_des_activites array for autocomplete ----- //


?>
<?php
echo form_open_multipart( base_url('engagement_crt/valider_ajout_engagement') ); 
?>

<form id="bc_form" class="pure-form pure-form-stacked" method="POST" action="<?php echo base_url('engagement_crt/valider_ajout_engagement');?>">
    <fieldset>
        <legend> اضافة التزام جديد </legend>
        
        <div class="pure-g" >
          
            <div class="pure-u-1 pure-u-md-1-3 " style="width: 25%">
                <label for="article">المادة </label>
                <input  class="ltr" id="article" name="article" type="text" value="">
            </div>
			
			
	        <div class="pure-u-1 pure-u-md-1-3 " style="width: 25%">
			   <label> طبيعة الالتزام </label>
			   <select id="s1" class="arabic" name="nature">
			  				
			    <option value=1 >نفقة </option>
			    <option value=2 >توفير </option>
				 
			   </select>
			</div>
			
       </div>
	   </fieldset>

 
		
	<?php
	 $goupe=$this->session->userdata('user_group'); //access it
if($goupe=="admin"){
echo ('<input type="submit" id="ajouter" value="اضافة"  class="pure-button pure-button-primary" />
	 <a href="'.base_url('/budget_ctr/load/').'" class="pure-button pure-button-primary" >عودة</a>');
}else{
	echo ('<a href="#" class="pure-button-disabled pure-button-primary">اضافة</a>
	 <a href="'.base_url('/budget_ctr/load/').'" class="pure-button pure-button-primary" >عودة</a>');
}
?>
</form> 
<?php
if($erreur){
		echo 'عملية التحديث لم تتم بنجاح </br>';
		if(array_key_exists('article',$erreur)){
			echo '<div style="background-color : red; width:30%">حقل ادخال المادة  خاطئ </div></br>';
		}
		if(array_key_exists('num_engagement',$erreur)){
			echo '<div style="background-color : red; width:30%">حقل ادخال رقم الالتزام خاطئ</div> </br>';
		}
		if(array_key_exists('montant',$erreur)){
			echo '<div style="background-color : red; width:30%">حقل ادخال المبلغ خاطئ</div> </br>';
		}
		
		
	}
?>
</body>

<script>
$(document).ready(function() {

var liste_charticle = <?php echo json_encode($liste_des_charticles); ?>;
$( "#article").autocomplete({source: liste_charticle});

});

$('#montant').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-rc').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    //var characterReg = /^([a-zA-Z0-9]{7,16})$/;
    var characterReg = /^([0-9]*[.]{0,1}[0-9]*)$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-rc" flag="required" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});

$('#article').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-rc').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    //var characterReg = /^([a-zA-Z0-9]{7,16})$/;
    var characterReg = /^([0-9a-zA-Z-_]+)$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-rc" flag="required" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});

$('#num_engagement').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-rc').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    //var characterReg = /^([a-zA-Z0-9]{7,16})$/;
    var characterReg = /^([0-9]+)$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-rc" flag="required" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});
</script>

</html>